package com.kobeliu.controller;

import com.kobeliu.pojo.bo.CandFollowHrBO;
import com.kobeliu.pojo.bo.HrReadCandBO;
import com.kobeliu.result.GraceJSONResult;
import com.kobeliu.service.CountsService;
import com.kobeliu.utils.PagedGridResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/counts")
@Slf4j
public class CountsController {

    @Autowired
    private CountsService countsService;

    //=========================用户端 START========================================

    /**
     * 谁看过我
     * @param candUserId
     * @return
     */
    @PostMapping("getWhoLookMeCounts")
    public GraceJSONResult getWhoLookMeCounts(String candUserId){
        long count = countsService.getWhoLookMeCounts(candUserId);
        return GraceJSONResult.ok(count);
    }

    /**
     * 关注
     * @param candUserId
     * @return
     */
    @PostMapping("getCandFollowHrCounts")
    public GraceJSONResult getCandFollowHrCounts(String candUserId){

        long count = countsService.getCandFollowHrCounts(candUserId);
        return GraceJSONResult.ok(count);
    }

    /**
     * 收藏
     * @param candUserId
     * @return
     */
    @PostMapping("getCollectJobCounts")
    public GraceJSONResult getCollectJobCounts(String candUserId){
        Long count = countsService.getCollectJobCounts(candUserId);
        return GraceJSONResult.ok(count);
    }

    /**
     * 面试
     * @param candUserId
     * @return
     */
    @PostMapping("cand/getInterviewRecordCounts")
    public GraceJSONResult candGetInterviewRecordCounts(String candUserId){

        Long count = countsService.candGetInterviewRecordCounts(candUserId);
        return GraceJSONResult.ok(count);
    }

    @PostMapping("pagedCollectJobList")
    public GraceJSONResult pagedCollectJobList(String candUserId,Integer page, Integer pageSize){

        if(page == null) page = 0;
        if(pageSize == null) page = 10;

        PagedGridResult result = countsService.pagedCollectJobList(candUserId, page,pageSize);
        return GraceJSONResult.ok(result);
    }

    @PostMapping("pagedWhoLookMe")
    public GraceJSONResult pagedWhoLookMe(String candUserId,Integer page, Integer pageSize){

        if(page == null) page = 0;
        if(pageSize == null) page = 10;

        PagedGridResult result = countsService.pagedWhoLookMe(candUserId, page,pageSize);
        return GraceJSONResult.ok(result);
    }

    //addCollectJob
    @PostMapping("addCollectJob")
    public GraceJSONResult addCollectJob(String candUserId,String jobId){
        countsService.addCollectJob(candUserId,jobId);
        return GraceJSONResult.ok();
    }

    @PostMapping("removeCollectJob")
    public GraceJSONResult removeCollectJob(String candUserId,String jobId){
        countsService.removeCollectJob(candUserId,jobId);
        return GraceJSONResult.ok();
    }

    @PostMapping("followHr")
    public GraceJSONResult followHr(@RequestBody @Valid CandFollowHrBO bo){

        countsService.followHr(bo);
        return GraceJSONResult.ok();
    }

    @PostMapping("unfollowHr")
    public GraceJSONResult unfollowHr(String hrId,String candUserId){

        countsService.unfollowHr(hrId,candUserId);
        return GraceJSONResult.ok();
    }

    @PostMapping("pagedCandFollowHr")
    public GraceJSONResult pagedCandFollowHr(String candUserId,Integer page,Integer pageSize){

        if(page == null) page=0;
        if(pageSize == null) pageSize=10;
        PagedGridResult result = countsService.pagedCandFollowHr(candUserId,page,pageSize);
        return GraceJSONResult.ok(result);
    }

    //isCandCollectJob
    @PostMapping("isCandCollectJob")
    public GraceJSONResult isCandCollectJob(String candUserId,String jobId){

        boolean isCollect = countsService.isCandCollectJob(candUserId,jobId);
        return GraceJSONResult.ok(isCollect);
    }

    //=========================用户端 END==========================================


    //=========================HR端 START========================================

    //getWhoLookMeCounts

    /**
     * 收藏
     * @param hrId
     * @return
     */
    @PostMapping("getColletResumeCounts")
    public GraceJSONResult getColletResumeCounts(String hrId){

        //redis中取就可以
        Integer counts = countsService.getColletResumeCounts(hrId);

        return GraceJSONResult.ok(counts);
    }

    /**
     * 浏览
     * @param hrId
     * @return
     */
    @PostMapping("getReadResumeRecordCounts")
    public GraceJSONResult getReadResumeRecordCounts(String hrId){

        long count = countsService.getReadResumeRecordCounts(hrId);
        return GraceJSONResult.ok(count);
    }

    /**
     * 面试
     * @param hrId
     * @return
     */
    @PostMapping("hr/getInterviewRecordCounts")
    public GraceJSONResult hrGetInterviewRecordCounts(String hrId){
        Long count = countsService.hrGetInterviewRecordCounts(hrId);
        return GraceJSONResult.ok(count);
    }

    /**
     * 职位数
     * @param hrId
     * @return
     */
    @PostMapping("hr/jobCounts")
    public GraceJSONResult hrJobCounts(String hrId){

        long count = countsService.hrJobCounts(hrId);
        return GraceJSONResult.ok(count);
    }

    /**
     * 收藏简历
     * @param hrId
     * @param resumeExpectId
     * @return
     */
    @PostMapping("addCollectResume")
    public GraceJSONResult addCollectResume(String hrId,String resumeExpectId){
        countsService.addCollect(hrId,resumeExpectId);
        return GraceJSONResult.ok();
    }


    /**
     * 取消收藏简历
     * @param hrId
     * @param resumeExpectId
     * @return
     */
    @PostMapping("removeCollectResume")
    public GraceJSONResult removeCollectResume(String hrId,String resumeExpectId){
        countsService.removeCollect(hrId,resumeExpectId);
        return GraceJSONResult.ok();
    }

    /**
     * 查询hr是否收藏简历
     * @param hrId
     * @param resumeExpectId
     * @return
     */
    @PostMapping("isHrCollectResume")
    public GraceJSONResult isHrCollectResume(String hrId,String resumeExpectId){

        boolean isExist = countsService.isHrCollectResume(hrId, resumeExpectId);
        return GraceJSONResult.ok(isExist);
    }

    //pagedCollectJobList?candUserId=1819750741745848321&page=0&pageSize=5
    @PostMapping("pagedCollectResumeList")
    public GraceJSONResult pagedCollectResumeList(String hrId,Integer page, Integer pageSize){

        if(page == null) page = 0;
        if(pageSize == null) page = 10;

        PagedGridResult result = countsService.pagedCollectResumeList(hrId, page,pageSize);
        return GraceJSONResult.ok(result);
    }

    @PostMapping("addReadResumeRecord")
    public GraceJSONResult addReadResumeRecord(String hrId,String resumeExpectId){

        countsService.addReadResumeRecord(hrId,resumeExpectId);

        return GraceJSONResult.ok();
    }


    //pagedReadResumeRecordList

    @PostMapping("pagedReadResumeRecordList")
    public GraceJSONResult pagedReadResumeRecordList(String hrId,Integer page,Integer limit){

        if(page == null) page=0;
        if(limit == null) limit=10;
        PagedGridResult result = countsService.pagedReadResumeRecordList(hrId,page,limit);

        return GraceJSONResult.ok(result);
    }

    //hrLookCand
    @PostMapping("hrLookCand")
    public GraceJSONResult hrLookCand(@RequestBody HrReadCandBO bo){

        countsService.hrLookCand(bo);

        return GraceJSONResult.ok();
    }

    /**
     * 查询当前hr是否被关注
     * @param hrId
     * @param candUserId
     * @return
     */
    //doseCandFollowHr
    @PostMapping("doseCandFollowHr")
    public GraceJSONResult doseCandFollowHr(String hrId,String candUserId){

        boolean isFollow = countsService.doseCandFollowHr(hrId,candUserId);

        return GraceJSONResult.ok(isFollow);
    }

    //=========================HR端 END==========================================


}
